package net.monare.mifss.configurations.pojo;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by kristan_uros on 2.4.2014.
 */
@XStreamAlias("StorageSetDef")
public class StorageSetDef implements Comparable<StorageSetDef>{

    @XStreamAsAttribute
    private String name;

    private String description;

    @Override
    public int compareTo(StorageSetDef other) {
        return this.name.compareTo(other.getName());
    }

    @XStreamAsAttribute
    private boolean locked = false;

    @XStreamAsAttribute
    private String lockedBy;

    private Set<StorageDef> storageDefList = new HashSet<>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return "StorageSetDef{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", locked=" + locked +
                ", lockedBy='" + lockedBy + '\'' +
                ", storageDefList=" + storageDefList +
                '}';
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean isLocked() {
        return locked;
    }

    public void setLocked(boolean locked) {
        this.locked = locked;
    }

    public String getLockedBy() {
        return lockedBy;
    }

    public void setLockedBy(String lockedBy) {
        this.lockedBy = lockedBy;
    }

    public Set<StorageDef> getStorageDefList() {
        return storageDefList;
    }

    public void addStorageDef(StorageDef storageDef) {
        storageDef.setStorageSetDef(this);
        storageDefList.add(storageDef);
    }

    public void removeStorageDef(StorageDef storageDef) {
        storageDefList.remove(storageDef);
    }

    public void setStorageDefList(Set<StorageDef> storageDefList) {
        this.storageDefList = storageDefList;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        StorageSetDef that = (StorageSetDef) o;

        if (!name.equals(that.name)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return name.hashCode();
    }
}
